#!/usr/bin/env python
#
# Copyright 2010 The Closure Library Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


"""Unit test for source."""




import unittest

import jsdocdeps

class JsDocDepsCase(unittest.TestCase):
  """Unit test for source.  Tests the parser on a known source input."""

  def testGetJsDocDependencies(self):
    provides, requires = jsdocdeps.GetJsDocDependencies(_TEST_JSDOC_SOURCE)

    self.assertEqual(set(['goog.dom', 'goog.events.EventType']), requires)
    self.assertEqual(set(['foo.bar.TacoTruck', 'foo.bar']), provides)

  def testGetJsDocDependenciesForFunctionSyntax(self):
    provides, requires = jsdocdeps.GetJsDocDependencies(_TEST_JSDOC_SOURCE_FUNCTION)
    self.assertEqual(set(['Foodstuff']), provides)

_TEST_JSDOC_SOURCE_FUNCTION = """
/**
 * @constructor
 * @class Foodstuff
 */
function Foodstuff(cat, bear) {

}
"""

_TEST_JSDOC_SOURCE = """// Fake copyright notice

/**
 * @fileoverview This is my file.
 * @requires goog.dom
 * @requires goog.events.EventType
 * @namespace foo.bar
 */

/**
 * @constructor
 * @class foo.bar.TacoTruck
 */
foo.bar.TacoTruck = function() {

};
"""

if __name__ == '__main__':
  unittest.main()

